
export default class Random {

    protected seed: number;

    public constructor(seed: number) {
        this.seed = seed;
    }

    /**
     * 随机范围函数
     * @returns 
     */
    public next(): number {
        this.seed = (this.seed * 9301 + 49297) % 233280;
        return this.seed / (233280.0);
    }

    /**
     * 随机范围函数
     * @param min 
     * @param max 
     * @returns 
     */
    public nextInt(min: number, max: number): number {
        let num = min + Math.floor(this.next() * (max - min + 1));
        if (num > max) num = max;
        return num;
    }

    /**
     * 随机范围函数
     * @param min 
     * @param max 
     * @returns 
     */
    public nextFloat(min: number, max: number): number {
        let num = min + this.next() * (max - min + 1);
        if (num > max) num = max;
        return num;
    }
}